var Resource = {};

Resource.upload = function(){
	//var url = "../servlet/resourceUploadService"
	//var url = "../servlet/uploadService"
	var url = context+"/manager/fileupload!resourceUpload.action";
	var fileName = $("#uploadFile").val();
	if (fileName == '') {
		alert("上传文件不能为空,请选择文件,继续上传!");
		return false;
	}
	
	var fileNameArray = fileName.split("\\");
	var imageOriginalName = fileNameArray[fileNameArray.length-1];
	$("#fileName").attr("value",imageOriginalName);

	var myForm = $("#upload");
	myForm.attr("action",url);
	myForm.submit();
	
	
//	var params = $('#upload').serialize();
//	url += "?"+params;
	
	
//	$('#upload').form("submit",{// 表单提交
//		url : url,
//		onSubmit : function() {
//			alert(url);
//		},
//		success : function(data) {
//			window.location.href = "resource!list.action";
//			alert(data);
//			var jsonData = eval("(" + data + ")");
//			if(jsonData.over_file_size_limit){//附件不能超过4k
//				window.location.href = "resource!addResource.action";
//				alert(jsonData.message);
//			}else{
//				window.location.href = "resource!list.action";
//				alert(jsonData.message);
//				
//			}
//		}
//		});
	
	
//	$('#upload').form('submit', {
//        url:url,
//        onSubmit: function(){
//                // do some check
//                // return false to prevent submit;
//        },
//        success : function(data) {
//        	alert("ddd");
//        	alert(data.msg);
//        	window.location.href = "resource!list.action";
//               // alert(data)
//        }
//	});

}

Resource.list = function(){
	var url = "resource!getAllResource.action";
	$('#resourceList').datagrid({
		width:768,
		height:'auto',
		striped: true,
		url:url,
		remoteSort: false,
		idField:'id',
		columns:[[
					{field:'name',title:'资源名',width:100,align:'center'},
					{field:'addUserName',title:'上传者',width:120,align:'center'},
					{field:'needPoint',title:'所需积分',width:150,align:'center'},
					{field:'description',title:'描述',width:100,align:'center'},
					{field:'addDate',title:'上传日期',width:145,align:'center'},
					{field:'id',title:'操作',width:119,align:'center',formatter:function(value,rec){
						return "<a  href='"+context+"/manager/resourcedownloader.action?filePathName="+rec.url+"&fileName="+rec.name+"' style='color:blue'>下载</a> ";
					}}
				]],
		pagination:true,
		loadMsg:'正在加载数据,请等待...',
		rownumbers:true
	});
	var p = $('#userListTable').datagrid('getPager');
	if (p){
		$(p).pagination({
			showPageList:false,
			beforePageText:'第',
			afterPageText:"页，共<font color='blue'> {pages} </font>页",
			displayMsg:"当前显示 <font color='red'>{from}</font> 到 <font color='red'>{to}</font> 条记录，共<font color='red'> {total} </font>条记录",
		});
	}
}